//
//  LocTableViewCell.m
//  chanyou
//
//  Created by 高爽 on 15-1-5.
//  Copyright (c) 2015年 wanli. All rights reserved.
//

#import "LocTableViewCell.h"

#import "AttractionsViewController.h"

#import "Masonry.h"

#import "CustomButton.h"

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

@implementation LocTableViewCell
- (void)dealloc
{
    [_descrip release];
    [_loc release];
    [_pic release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.heightLoc = _heightLoc;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.pic = [[UIImageView alloc] init];
        [self.contentView addSubview:_pic];
        [_pic release];
        
        self.descrip = [[UILabel alloc] init];
        _descrip.font = [UIFont systemFontOfSize:15.0];
        _descrip.numberOfLines = 0;
        [self.contentView addSubview:_descrip];
        [_descrip release];
        
        self.loc = [[CustomButton alloc] init];
        NSLog(@"height to = %f", _heightLoc);
        [_loc setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_loc setBackgroundImage:[UIImage imageNamed:@"newbutton"] forState:UIControlStateNormal];
        _loc.titleLabel.font = [UIFont systemFontOfSize:14];
        // 靠左
        _loc.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [self.contentView addSubview:_loc];
        [_loc release];
        
        
    } return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
//    [_pic mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.contentView.mas_left).offset(5);
//        make.top.equalTo(self.contentView.mas_top).offset(5);
//        // self.frame = [[UIScreen mainScreen] bounds];
//        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 10, SCREEN_HEIGHT / 3));
//    }];
//
    
//    [_descrip mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.bottom.right.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(SCREEN_HEIGHT / 3, 5, 10 + 10 + 15, 5));
//        
//        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 10, SCREEN_HEIGHT / 2));
//    }];
    
    if (! _descrip.text.length == 0) {
        [_pic mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(5);
            make.top.equalTo(self.contentView.mas_top).offset(5);
            // self.frame = [[UIScreen mainScreen] bounds];
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 10, SCREEN_HEIGHT / 3));
        }];
        

        
        [_loc mas_makeConstraints:^(MASConstraintMaker *make) {
            //        make.top.left.bottom.right.equalTo(self.descrip).with.insets(UIEdgeInsetsMake(SCREEN_HEIGHT / 3 + 20, 5, 5, SCREEN_WIDTH - 95));
            make.left.equalTo(self.descrip.mas_left).offset(0);
            make.top.equalTo(self.descrip.mas_bottom).offset(2);
            
            make.size.mas_equalTo(CGSizeMake(100, 20));
        }];
        [_descrip mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.bottom.right.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(SCREEN_HEIGHT / 3, 5, 10 + 10 + 15, 5));
            
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 10, SCREEN_HEIGHT / 2));
        }];
    } else if (_descrip.text.length == 0) {
        
        
        [_descrip mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.left.bottom.right.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(SCREEN_HEIGHT / 3-5, 5, 15, 5));
            
            make.size.mas_equalTo(CGSizeMake(0, 0));
        }];
    
        [_loc mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.pic.mas_left).offset(0);
            make.top.equalTo(self.pic.mas_bottom).offset(10);
            // make.bottom.equalTo(self.contentView.mas_bottom).offset(5);
            make.size.mas_equalTo(CGSizeMake(100, 20));
        }];
    }
    
//    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15.0f], NSFontAttributeName, nil];
//    
//    CGRect rect = [self.descrip.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 10, 700) options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:dic context:nil];
//    _descrip.frame = CGRectMake(5, SCREEN_WIDTH / 2 + 10, SCREEN_WIDTH - 10, rect.size.height);
//
//    
//    self.loc.frame = CGRectMake(5, (rect.size.height + SCREEN_WIDTH / 2) + 15, 100, 15);
}

- (void)awakeFromNib {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
